Skip to content

[BeEF] Fix file handle leak in copyright_update.rb#3557

Open
mitre88 wants to merge 1 commit intobeefproject:masterfrom
mitre88:fix/file-handle-leak-copyright-update
Open

[BeEF] Fix file handle leak in copyright_update.rb#3557
mitre88 wants to merge 1 commit intobeefproject:masterfrom
mitre88:fix/file-handle-leak-copyright-update

Conversation

@mitre88
Copy link
Copy Markdown

@mitre88 mitre88 commented May 1, 2026

Summary

Fixes a file handle leak in tools/maintenance/copyright_update.rb.

Issue

The log file was opened using File.open() without a block/context manager:

log_file = File.open('copyright_update.log', 'w')

If an exception occurred before log_file.close was called, the file descriptor would leak. This is especially problematic in a maintenance script that processes many files.

Fix

  • Wrap File.open in a block (File.open(...) do |log_file|) so the file is automatically closed when the block ends
  • Move the function definition and main processing logic inside the block
  • Remove the explicit log_file.close call since it's no longer needed

- Wrap File.open in a context manager (block) instead of storing
  the file handle in a local variable
- Move function definition and main logic inside the block to
  ensure proper cleanup
- Fix potential file descriptor leak if an exception occurred
  before log_file.close was called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant